package com.mz.mattress.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mz.mattress.admin.api.req.BlackQueryReq;
import com.mz.mattress.admin.mapper.BlackMapper;
import com.mz.mattress.admin.service.BlackService;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.Black;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Set;
import java.util.stream.Collectors;

@Slf4j
@Service
public class BlackServiceImpl implements BlackService {

    @Autowired
    private BlackMapper blackMapper;

    @Override
    public Result<IPage<Black>> listPage(BlackQueryReq req) {
        Page<Black> listPage = blackMapper.listPage(req.newPage(), req.getMerchantId(), null, null);
        return Result.ok(listPage);
    }

    @Override
    public Result<Black> getById(Integer id) {
        Black black = blackMapper.selectById(id);
        if (black == null) {
            return Result.fail("找不到广告");
        }
        return Result.ok(black);
    }

    @Override
    public Result add(Black black) {
        blackMapper.insert(black);
        return Result.ok(black.getId());
    }

    @Override
    public Result updateById(Black black) {
        blackMapper.updateById(black);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        blackMapper.deleteBatchIds(ids);
        return Result.ok();
    }

    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();

        Set<String> set = list.stream().collect(Collectors.toSet());

        System.out.println(set.size());

    }
}
